package qeb.handheldmedical.adapter;

import org.json.JSONArray;
import org.json.JSONObject;

import qeb.handheldmedical.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InpatientInfoAdapter extends BaseAdapter{

	private static final String TAG = "InpatientInfoJsonArray";
	
	//private ImageSwitcher mImageLoader;
	private int mCount;
	private Context mContext;
	private JSONArray mInpatientInfoJsonArray =null;
	
	public InpatientInfoAdapter(int count, Context context, JSONArray InpatientInfoJsonArray) {
		this.mCount = count;
		this.mContext = context;
		this.mInpatientInfoJsonArray = InpatientInfoJsonArray;
		//mImageLoader = new ImageSwitcher(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder = null;
		convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_inpatient_info, null);
			viewholder = new ViewHolder();
			viewholder.tv_XM = (TextView)convertView.findViewById(R.id.tv_XM);
			viewholder.tv_SEXNAME = (TextView)convertView.findViewById(R.id.tv_SEXNAME);
			viewholder.tv_nl = (TextView)convertView.findViewById(R.id.tv_nl);
			viewholder.tv_bah = (TextView)convertView.findViewById(R.id.tv_bah);
			viewholder.tv_bqname = (TextView)convertView.findViewById(R.id.tv_bqname);
			viewholder.tv_ch = (TextView)convertView.findViewById(R.id.tv_ch);
			viewholder.tv_RACENAME = (TextView)convertView.findViewById(R.id.tv_RACENAME);
			viewholder.tv_MARRIAGENAME = (TextView)convertView.findViewById(R.id.tv_MARRIAGENAME);
			viewholder.tv_CAREERNAME = (TextView)convertView.findViewById(R.id.tv_CAREERNAME);			
			viewholder.tv_CSD = (TextView)convertView.findViewById(R.id.tv_CSD);
			viewholder.tv_FEENAME = (TextView)convertView.findViewById(R.id.tv_FEENAME);
			viewholder.tv_DNAME = (TextView)convertView.findViewById(R.id.tv_DNAME);
			viewholder.tv_JTZZ = (TextView)convertView.findViewById(R.id.tv_JTZZ);
			viewholder.tv_JTDH = (TextView)convertView.findViewById(R.id.tv_JTDH);
			viewholder.tv_CSRQ = (TextView)convertView.findViewById(R.id.tv_CSRQ);
			//viewholder.tv_JG = (TextView)convertView.findViewById(R.id.tv_JG);
			viewholder.tv_IDCARD = (TextView)convertView.findViewById(R.id.tv_IDCARD);
			viewholder.tv_SCHOOLNAME = (TextView)convertView.findViewById(R.id.tv_SCHOOLNAME);
			viewholder.tv_ZD = (TextView)convertView.findViewById(R.id.tv_ZD);
			viewholder.tv_ZYSJ = (TextView)convertView.findViewById(R.id.tv_ZYSJ);
			viewholder.tv_CYSJ = (TextView)convertView.findViewById(R.id.tv_CYSJ);
			viewholder.tv_KNAME = (TextView)convertView.findViewById(R.id.tv_KNAME);
			viewholder.tv_LXRXM1 = (TextView)convertView.findViewById(R.id.tv_LXRXM1);
			viewholder.tv_LXRDH1 = (TextView)convertView.findViewById(R.id.tv_LXRDH1);
			convertView.setTag(viewholder);
			
			try {
				JSONObject ipif = mInpatientInfoJsonArray.getJSONObject(position);
				if(ipif!=null)
				{

					viewholder.tv_XM.setText("姓        名:  "+ipif.getString("XM"));
					viewholder.tv_SEXNAME.setText("性        别:  "+ipif.getString("SEXNAME"));
					viewholder.tv_nl.setText("年        龄:  "+ipif.getString("AGE")+"岁:");
					viewholder.tv_bah.setText("住  院  号:  "+ipif.getString("BAH"));
					viewholder.tv_bqname.setText("当前病区:  "+ipif.getString("BQNAME"));
					viewholder.tv_ch.setText("床        号:  "+ipif.getString("CH"));
					viewholder.tv_RACENAME.setText("民        族:  "+ipif.getString("RACENAME"));
					viewholder.tv_MARRIAGENAME.setText("婚        姻:  "+ipif.getString("MARRIAGENAME"));
					viewholder.tv_CAREERNAME.setText("职        业:  "+ipif.getString("CAREERNAME"));			
					viewholder.tv_CSD.setText("出  生  地:  "+ipif.getString("CSD"));
					viewholder.tv_FEENAME.setText("费用类型:  "+ipif.getString("FEENAME"));
					viewholder.tv_DNAME.setText("主管医生:  "+ipif.getString("DNAME"));
					viewholder.tv_JTZZ.setText("家庭地址:  "+ipif.getString("JTZZ"));
					viewholder.tv_JTDH.setText("家庭电话:  "+ipif.getString("JTDH"));
					viewholder.tv_CSRQ.setText("出生日期:  "+ipif.getString("CSRQ"));
					//viewholder.tv_JG.setText("籍贯:"+ipif.getString("JG"));
					viewholder.tv_IDCARD.setText("身  份  证:  "+ipif.getString("IDCARD"));
					viewholder.tv_SCHOOLNAME.setText("学        历:  "+ipif.getString("SCHOOLNAME"));
					viewholder.tv_ZD.setText("门诊诊断:  "+ipif.getString("ZD"));
					viewholder.tv_ZYSJ.setText("入院时间:  "+ipif.getString("ZYSJ"));
					viewholder.tv_CYSJ.setText("出院时间:  "+ipif.getString("CYSJ"));
					viewholder.tv_KNAME.setText("当前科室:  "+ipif.getString("KNAME"));
					viewholder.tv_LXRXM1.setText("联  系  人:  "+ipif.getString("LXRXM1"));
					viewholder.tv_LXRDH1.setText("联系电话:  "+ipif.getString("LXRDH1"));
					
				}
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(TAG, e.toString());
			}
		
		return convertView;
	}
	
	static class ViewHolder {
		//ImageView imgPatient;
		TextView tv_XM;
		TextView tv_SEXNAME;
		TextView tv_nl;
		TextView tv_bah;
		TextView tv_bqname;
		TextView tv_ch;
		TextView tv_RACENAME;
		TextView tv_MARRIAGENAME;
		TextView tv_CAREERNAME;
		TextView tv_CSD;
		TextView tv_FEENAME;
		TextView tv_DNAME;
		TextView tv_JTZZ;
		TextView tv_JTDH;
		TextView tv_CSRQ;
		//TextView tv_JG;
		TextView tv_IDCARD;
		TextView tv_SCHOOLNAME;
		TextView tv_ZD;
		TextView tv_ZYSJ;
		TextView tv_CYSJ;
		TextView tv_KNAME;
		TextView tv_LXRXM1;
		TextView tv_LXRDH1;
	}
}